import tkinter
import tkinter.messagebox
import random
import threading
import itertools
import time
root=tkinter.Tk()
root.title("随机选人")
root.geometry("260x180+400+300")
def closeWindow():
    root.flag=time.sleep(0.1)
    root.destroy()
root.protocol("WM_DELETE_WINDOW",closeWindow)
students=['姚林涛','姚林涛','姚林涛,''姚林涛','姚林涛','李石俊','张鑫飞','小百合','陈启超']
root.flag=False
def switch():
  root.flag=True
  t=students[:]
  random.shuffle(t)
  t=itertools.cycle(t)
  while root.flag:
    IbFirst['text']=IbSecond['text']
    IbSecond['text']=IbThird['text']
    IbThird['text']=next(t)
    time.sleep(0.1)
def btnStartClick():
  t=threading.Thread(target=switch)
  t.start()
  btnStart['state']='disabled'
  btnStop['state']='normal'
btnStart=tkinter.Button(root,
                text='开始',
                command=btnStartClick)
btnStart.place(x=30,y=10,width=80,height=20)
def btnStopClick():
  root.flag=False
  time.sleep(0.3)
  tkinter.messagebox.showinfo("恭喜",
                              "你中奖了:"+IbSecond['text'])
  btnStart['state']='normal'
  btnStop['state']='disabled'
btnStop=tkinter.Button(root,
                       text='停止',
                       command=btnStopClick)
btnStop['state']='disabled'                       
btnStop.place(x=150,y=10,width=80,height=20)
IbFirst=tkinter.Label(root,text=' ')
IbFirst.place(x=80,y=60,width=100,height=20)
IbSecond=tkinter.Label(root,text=' ')
IbSecond['fg']='red'
IbSecond.place(x=80,y=90,width=100,height=20)
IbThird=tkinter.Label(root,text=' ')
IbThird.place(x=80,y=120,width=100,height=20)
root.mainloop()